//存放主要交互逻辑的js代码

var yongan = {
	URL : {
		exposer : function() {
			return '/user/exposer';
		},
		userAdd : function() {
			return '/user/adddo';
		},
		userUpdate : function() {
			return '/user/update';
		},
		userDelete : function(userId) {
			return '/user/'+userId+'/delete';
		},
		userList : function() {
			return '/user/userlist';
		},
		deptList : function() {
			return '/dept/deptlist';
		},
		deptDelete : function(deptId) {
			return '/dept/'+deptId+'/delete';
		},
		deptAdd : function() {
			return '/dept/adddo';
		},
		deptUpdate : function() {
			return '/dept/update';
		},
		businessAdd : function() {
			return '/business/adddo';
		},
		businessUpdate : function() {
			return '/business/update';
		},
		businessDelete : function(Id) {
			return '/business/'+Id+'/delete';
		},
		businessList : function(){
			return "/business/0/businesslist";
		},
		warehouseAdd : function() {
			return '/warehouse/adddo';
		},
		warehouseUpdate : function() {
			return '/warehouse/update';
		},
		warehouseDelete : function(Id) {
			return '/warehouse/'+Id+'/delete';
		},
		warehouseList : function(){
			return "/warehouse/warehouselist";
		},
		goodtypeAdd : function() {
			return '/goodtype/adddo';
		},
		goodtypeUpdate : function() {
			return '/goodtype/update';
		},
		goodtypeDelete : function(Id) {
			return '/goodtype/'+Id+'/delete';
		},
		goodtypeList : function(){
			return "/goodtype/goodtypelist";
		},
		goodsinformationAdd : function() {
			return '/goodsinformation/adddo';
		},
		goodsinformationUpdate : function() {
			return '/goodsinformation/update';
		},
		goodsinformationDelete : function(Id) {
			return '/goodsinformation/'+Id+'/delete';
		},
		goodsinformationList : function(){
			return "/goodsinformation/goodsinformationlist";
		},
		outsourcingInAdd : function() {
			return '/outsourcingin/adddo';
		},
		outsourcingInUpdate : function() {
			return '/outsourcingin/update';
		},
		outsourcingInDelete : function(Id) {
			return '/outsourcingin/'+Id+'/delete';
		},
		outsourcingInList : function(){
			return "/outsourcingin/outsourcinginlist";
		},
		othergoodoutAdd : function() {
			return '/othergoodout/adddo';
		},
		othergoodoutUpdate : function() {
			return '/othergoodout/update';
		},
		othergoodoutDelete : function(Id) {
			return '/othergoodout/'+Id+'/delete';
		},
		othergoodoutList : function(){
			return "/othergoodout/othergoodoutlist";
		},
		transferAdd : function() {
			return '/transfer/adddo';
		},
		transferUpdate : function() {
			return '/transfer/update';
		},
		transferDelete : function(Id) {
			return '/transfer/'+Id+'/delete';
		},
		transferList : function(){
			return "/transfer/transferlist";
		},
		purchaseAdd : function() {
			return '/purchase/adddo';
		},
		purchaseUpdate : function() {
			return '/purchase/update';
		},
		purchaseDelete : function(Id) {
			return '/purchase/'+Id+'/delete';
		},
		purchaseList : function(){
			return "/purchase/purchaselist";
		},
		purchaseinAdd : function() {
			return '/purchasein/adddo';
		},
		purchaseinUpdate : function() {
			return '/purchasein/update';
		},
		purchaseinDelete : function(Id) {
			return '/purchasein/'+Id+'/delete';
		},
		purchaseinList : function(){
			return "/purchasein/purchaseinlist";
		},
		salesOrderAdd : function() {
			return '/salesorder/adddo';
		},
		salesOrderUpdate : function() {
			return '/salesorder/update';
		},
		salesOrderDelete : function(Id) {
			return '/salesorder/'+Id+'/delete';
		},
		salesOrderList : function(){
			return "/salesorder/salesorderlist";
		},
		salesOrderAdd : function() {
			return '/salesorder/adddo';
		},
		salesOutUpdate : function() {
			return '/salesout/update';
		},
		salesOutDelete : function(Id) {
			return '/salesout/'+Id+'/delete';
		},
		salesOutList : function(){
			return "/salesout/salesoutlist";
		},
		purchasereturnAdd : function() {
			return '/purchasereturn/adddo';
		},
		purchasereturnUpdate : function() {
			return '/purchasereturn/update';
		},
		purchasereturnDelete : function(Id) {
			return '/purchasereturn/'+Id+'/delete';
		},
		purchasereturnList : function(){
			return "/purchasereturn/purchasereturnlist";
		},
		salesreturnAdd : function() {
			return '/salesreturn/adddo';
		},
		salesreturnUpdate : function() {
			return '/salesreturn/update';
		},
		salesreturnDelete : function(Id) {
			return '/salesreturn/'+Id+'/delete';
		},
		salesreturnList : function(){
			return "/salesreturn/salesreturnlist";
		},
		productstructurelistAdd : function() {
			return '/productstructurelist/adddo';
		},
		productstructurelistUpdate : function() {
			return '/productstructurelist/update';
		},
		productstructurelistDelete : function(Id) {
			return '/productstructurelist/'+Id+'/delete';
		},
		productstructurelistList : function(){
			return "/productstructurelist/productstructurelistlist";
		},
		productionplanAdd : function() {
			return '/productionplan/adddo';
		},
		productionplanUpdate : function() {
			return '/productionplan/update';
		},
		productionplanDelete : function(Id) {
			return '/productionplan/'+Id+'/delete';
		},
		productionplanList : function(){
			return "/productionplan/productionplanlist";
		},
		processprocessAdd : function() {
			return '/processprocess/adddo';
		},
		processprocessUpdate : function() {
			return '/processprocess/update';
		},
		processprocessDelete : function(Id) {
			return '/processprocess/'+Id+'/delete';
		},
		processprocessList : function(type){
			return "/processprocess/processprocesslist?type="+type;
		},
		goodassembleAdd : function() {
			return '/goodassemble/adddo';
		},
		goodassembleUpdate : function() {
			return '/goodassemble/update';
		},
		goodassembleDelete : function(Id) {
			return '/goodassemble/'+Id+'/delete';
		},
		goodassembleList : function(){
			return "/goodassemble/goodassemblelist";
		},
		flowinfoAdd : function() {
			return '/flowinfo/adddo';
		},
		flowinfoUpdate : function() {
			return '/flowinfo/update';
		},
		flowinfoDelete : function(Id) {
			return '/flowinfo/'+Id+'/delete';
		},
		flowinfoList : function(){
			return "/flowinfo/flowinfolist";
		}
		
	},
	doAdd : function() {

	},
	format :function (now,mask){
        var d = now;
        var zeroize = function (value, length)
        {
            if (!length) length = 2;
            value = String(value);
            for (var i = 0, zeros = ''; i < (length - value.length); i++)
            {
                zeros += '0';
            }
            return zeros + value;
        };
     
        return mask.replace(/"[^"]*"|'[^']*'|\b(?:d{1,4}|m{1,4}|yy(?:yy)?|([hHMstT])\1?|[lLZ])\b/g, function ($0)
        {
            switch ($0)
            {
                case 'd': return d.getDate();
                case 'dd': return zeroize(d.getDate());
                case 'ddd': return ['Sun', 'Mon', 'Tue', 'Wed', 'Thr', 'Fri', 'Sat'][d.getDay()];
                case 'dddd': return ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][d.getDay()];
                case 'M': return d.getMonth() + 1;
                case 'MM': return zeroize(d.getMonth() + 1);
                case 'MMM': return ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][d.getMonth()];
                case 'MMMM': return ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][d.getMonth()];
                case 'yy': return String(d.getFullYear()).substr(2);
                case 'yyyy': return d.getFullYear();
                case 'h': return d.getHours() % 12 || 12;
                case 'hh': return zeroize(d.getHours() % 12 || 12);
                case 'H': return d.getHours();
                case 'HH': return zeroize(d.getHours());
                case 'm': return d.getMinutes();
                case 'mm': return zeroize(d.getMinutes());
                case 's': return d.getSeconds();
                case 'ss': return zeroize(d.getSeconds());
                case 'l': return zeroize(d.getMilliseconds(), 3);
                case 'L': var m = d.getMilliseconds();
                    if (m > 99) m = Math.round(m / 10);
                    return zeroize(m);
                case 'tt': return d.getHours() < 12 ? 'am' : 'pm';
                case 'TT': return d.getHours() < 12 ? 'AM' : 'PM';
                case 'Z': return d.toUTCString().match(/[A-Z]+$/);
                // Return quoted strings with the surrounding quotes removed
                default: return $0.substr(1, $0.length - 2);
            }
        });
    },
	dialog : {
		upname:"",
		upid:"",
		other:"",
		other1:"",
		other2:"",
		other3:"",
		other4:"",
		showdialog : function(url,id,upname,upid){
			$("#"+id+"").html('<iframe src="' + url + '" frameborder="0" height="100%" width="100%" id="dialogFrame" scrolling="auto"></iframe>');
			$("#"+id+"").dialog();
			this.upname = upname;
			this.upid = upid;
		},
		showdialog_gys : function(url,id,upname,upid,other,other1){
			$("#"+id+"").html('<iframe src="' + url + '" frameborder="0" height="100%" width="100%" id="dialogFrame" scrolling="auto"></iframe>');
			$("#"+id+"").dialog();
			this.upname = upname;
			this.upid = upid;
			this.other = other;
			this.other1 = other1;
		},
		showdialog_hpxx : function(url,id,upid,upname,other,other1,other2){
			$("#"+id+"").html('<iframe src="' + url + '" frameborder="0" height="100%" width="100%" id="dialogFrame" scrolling="auto"></iframe>');
			$("#"+id+"").dialog();
			this.upid = upid;
			this.upname = upname;
			this.other = other;
			this.other1 = other1;
			this.other2 = other2;
		},
		showdialog_hpxx_list : function(url,id,upid,upname,other,other1,other2,other3,other4){
			$("#"+id+"").html('<iframe src="' + url + '" frameborder="0" height="100%" width="100%" id="dialogFrame" scrolling="auto"></iframe>');
			$("#"+id+"").dialog();
			this.upid = upid;
			this.upname = upname;
			this.other = other;
			this.other1 = other1;
			this.other2 = other2;
			this.other3 = other3;
			this.other4 = other4;
		},
		closedialog : function(id){
			$("#"+id+"").dialog('close');
		},
		adddept : function (checkId){
			$("#deptId").val(checkId.id);
			$("#deptName").val(checkId.name);
			$("#deptdialog").dialog('close');
		},
		adduser : function (checkId){
			$("#"+this.upid+"").val(checkId.id);
			$("#"+this.upname+"").val(checkId.name);
			$("#deptdialog").dialog('close');
		},
		addgys : function (checkId){
			$("#"+this.upid+"").val(checkId.id);
			$("#"+this.upname+"").val(checkId.name);
			$("#"+this.other+"").val(checkId.people);
			$("#"+this.other1+"").val(checkId.phone);
			$("#deptdialog").dialog('close');
		},
		addhpxx : function (checkId){
			$("input[name='"+this.upid+"']").val(checkId.id);
			$("input[name='"+this.upname+"']").val(checkId.name);
			$("input[name='"+this.other+"']").val(checkId.hpxh);
			$("input[name='"+this.other1+"']").val(checkId.dw);
			$("input[name='"+this.other2+"']").val(checkId.dj);
			$("input[name='"+this.other3+"']").val(checkId.rid);
			$("input[name='"+this.other4+"']").val(checkId.type);
			$("#deptdialog").dialog('close');
		}
	},
	zZs :function(num){
		if(!(/(^[1-9]\d*$)/.test(num))){
			alert("请输入正整数！"); 
			return false;
		}
		return true;
	}
};
function fenye(currentPage,totalPages,totalRecords,pagesize,type){
	var htmlContent = new Array();;
	htmlContent.push("<ul class='pagination'>");
	var content = $("resultlist");
	var uppage = parseInt(currentPage,10)-1;
	var nextpage = parseInt(currentPage,10)+1;
	if(uppage<=0){
		htmlContent.push("<li class='page-item disabled'><a class='page-link' href='#'>首页</a></li>");
		htmlContent.push("<li class='page-item disabled'><a class='page-link' href='#'>上一页</a></li>");
		//htmlContent.push("<ul class='pagination'>");
		//htmlContent.push("<li class='page-item disabled'><a class='page-link' href='/dept/deptlist?currentPage=${pb.totalPages}'>末页</a></li>");
	}else{
		htmlContent.push("<li class='page-item'><a class='page-link' href='"+type+"?currentPage=1'>首页</a></li>");
		htmlContent.push("<li class='page-item'><a class='page-link' href='"+type+"?currentPage="+uppage+"'>上一页</a></li>");
	}
	htmlContent.push("<li class='page-item active'><a class='page-link'>第"+currentPage+"页</a></li>");
	if(nextpage>parseInt(totalPages,10)){//首页
	    htmlContent.push("<li class='page-item disabled'><a class='page-link' href='#'>下一页</a></li>");
	    htmlContent.push("<li class='page-item disabled'><a class='page-link' href='#'>尾页</a></li>");
	}else{
	    htmlContent.push("<li class='page-item'><a class='page-link' href='"+type+"?currentPage="+nextpage+"'>下一页</a></li>");
	    htmlContent.push("<li class='page-item'><a class='page-link' href='"+type+"?currentPage="+totalPages+"'>尾页</a></li>");
	}
	htmlContent.push("<li class='page-item'><a class='page-link'>共"+totalRecords+"条,每页"+pagesize+"条,共"+totalPages+"页</a></li></ul>");
	htmlContent.push("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<ul style='margin-top: -90px;' class='pagination'><li class='page-item'><a class='page-link'>跳转到第<input type='text' style='width:30px;height:20px'  class='' id='gotopage' value='"+currentPage+"'>页</a></li>");
	htmlContent.push("<li class='page-item active'><div is='sure' class='btn btn-info' href='#' onclick='tiaozhuan("+totalPages+",\""+type+"\")'>确定</div></li></ul>");
	htmlContent.push("</ul>");
	document.getElementById("resultlist").innerHTML=htmlContent.join("");
}
function tiaozhuan(totalPages,type){
	var go=$("#gotopage").val();
	 var regexp = /^\d+$/;	 
	 if (!regexp.test(go)|| parseInt(go,10)<1 || parseInt(go,10)>parseInt(totalPages,10)) {
	 	Modal.alert({
                    msg: '请输入正确的页号',
                    title: '执行结果',
                    btnok: '确定',
                    btncl: '取消'
                }).on(function(e) {
                    return false;
                });
	 }
	 if(parseInt(go,10)<=parseInt(totalPages,10)){
		parent.changeIframe(type+"?currentPage="+go);
	 }
}
$(function() {
	//$( ".mydate" ).datepicker();
	window.Modal = function() {
	    var reg = new RegExp("\\[([^\\[\\]]*?)\\]", 'igm');
	    var alr = $("#ycf-alert");
	    var ahtml = alr.html();

	    //关闭时恢复 modal html 原样，供下次调用时 replace 用
	    //var _init = function () {
	    //alr.on("hidden.bs.modal", function (e) {
	    //  $(this).html(ahtml);
	    //});
	    //}();
	    /* html 复原不在 _init() 里面做了，重复调用时会有问题，直接在 _alert/_confirm 里面做 */

	    var _alert = function(options) {
	        alr.html(ahtml); // 复原
	        alr.find('.ok').removeClass('btn-success').addClass('btn-primary');
	        alr.find('.cancel').hide();
	        _dialog(options);

	        return {
	            on: function(callback) {
	                if (callback && callback instanceof Function) {
	                    alr.find('.ok').click(function() {
	                        callback(true)
	                    });
	                }
	            }
	        };
	    };

	    var _confirm = function(options) {
	        alr.html(ahtml); // 复原
	        alr.find('.ok').removeClass('btn-primary').addClass('btn-success');
	        alr.find('.cancel').show();
	        _dialog(options);

	        return {
	            on: function(callback) {
	                if (callback && callback instanceof Function) {
	                    alr.find('.ok').click(function() {
	                        callback(true)
	                    });

	                }
	            }
	        };
	    };

	    var _dialog = function(options) {
	        var ops = {
	            msg: "提示内容",
	            title: "操作提示",
	            btnok: "确定",
	            btncl: "取消"
	        };

	        $.extend(ops, options);

	      //  console.log(alr);

	        var html = alr.html().replace(reg,
	        function(node, key) {
	            return {
	                Title: ops.title,
	                Message: ops.msg,
	                BtnOk: ops.btnok,
	                BtnCancel: ops.btncl
	            } [key];
	        });

	        alr.html(html);
	        alr.modal({
	            width: 500,
	            backdrop: 'static'
	        });
	    }

	    return {
	        alert: _alert,
	        confirm: _confirm
	    }

	} ();
	});
